69 #include "TObjString.h"
79 #include <ext/hash_map>
86 using namespace __gnu_cxx;
87 using __gnu_cxx::hash_map;
131 virtual void algoEndJob ()
override;
134 int statCollectionFromMode(
const char*
tag)
const;
135 void bookDQMHistos(
const char* dqm_dir,
const char* tag);
138 void swapBFieldMode(
void);
141 void algoAnalyzeTheTree();
142 void algoComputeMPVandGain();
145 void getPeakOfLandau(TH1* InputHisto,
double* FitResults,
double LowRange=50,
double HighRange=5400);
146 bool IsGoodLandauFit(
double* FitResults);
148 void MakeCalibrationMap();
149 bool produceTagFilter();
226 unsigned int eventnumber =0;
266 template <
class T>
bool operator () (
const T& PseudoDetId1,
const T& PseudoDetId2) {
return PseudoDetId1==PseudoDetId2; }
270 __gnu_cxx::hash_map<unsigned int, stAPVGain*, __gnu_cxx::hash<unsigned int>,
isEqual >
APVsColl;
276 std::vector<string>::const_iterator it=dqm_tag_.begin();
277 while(it!=dqm_tag_.end()) {
278 if(*it==
std::string(tag))
return it-dqm_tag_.begin();
288 if(A->GetNbinsX() == B->GetNbinsX()){
291 for(
int x=0;
x<=B->GetNbinsX()+1;
x++){
292 for(
int y=0;y<=B->GetNbinsY()+1; y++){
293 A->SetBinContent(
x,y,A->GetBinContent(
x,y)+B->GetBinContent(
x,y));
393 EventPrefix_ = evtinfo_pset.getUntrackedParameter<
string>(
"prefix");
394 EventSuffix_ = evtinfo_pset.getUntrackedParameter<
string>(
"suffix");
399 TrackPrefix_ = track_pset.getUntrackedParameter<
string>(
"prefix");
400 TrackSuffix_ = track_pset.getUntrackedParameter<
string>(
"suffix");
415 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Setting " << dqm_dir <<
"in DQM and booking histograms for tag "
418 if ( strcmp(booked_dir.c_str(),dqm_dir)!=0 ) {
419 booked_dir = dqm_dir;
420 dbe->setCurrentFolder(dqm_dir);
424 if(stag.size()!=0 && stag[0]!=
'_') stag.insert(0,1,
'_');
439 Charge_Vs_Index[elepos] =
dbe->book2S(cvi.c_str() , cvi.c_str() , 88625, 0 , 88624,2000,0,4000);
458 const char * dqm_dir =
"AlCaReco/SiStripGainsHarvesting/";
465 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Switching calibration mode for endorsing BField status: "
476 auto const &
Det = tkGeom->dets();
480 unsigned int Index=0;
481 for(
unsigned int i=0;
i<
Det.size();
i++){
489 if(!DetUnit)
continue;
492 unsigned int NAPV = Topo.
nstrips()/128;
494 for(
unsigned int j=0;
j<NAPV;
j++){
510 APV->
x = DetUnit->position().basicVector().x();
511 APV->
y = DetUnit->position().basicVector().y();
512 APV->
z = DetUnit->position().basicVector().z();
513 APV->
Eta = DetUnit->position().basicVector().eta();
514 APV->
Phi = DetUnit->position().basicVector().phi();
515 APV->
R = DetUnit->position().basicVector().transverse();
516 APV->
Thickness = DetUnit->surface().bounds().thickness();
528 for(
unsigned int i=0;
i<
Det.size();
i++){
533 if(!DetUnit)
continue;
536 unsigned int NROCRow = Topo.
nrows()/(80.);
537 unsigned int NROCCol = Topo.
ncolumns()/(52.);
539 for(
unsigned int j=0;
j<NROCRow;
j++){
540 for(
unsigned int i=0;
i<NROCCol;
i++){
555 APV->
x = DetUnit->position().basicVector().x();
556 APV->
y = DetUnit->position().basicVector().y();
557 APV->
z = DetUnit->position().basicVector().z();
558 APV->
Eta = DetUnit->position().basicVector().eta();
559 APV->
Phi = DetUnit->position().basicVector().phi();
560 APV->
R = DetUnit->position().basicVector().transverse();
561 APV->
Thickness = DetUnit->surface().bounds().thickness();
591 double average_current = runInfo.
product()->m_avg_current;
595 return ( (isOn && !is0T) || (!isOn && is0T) );
613 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Switching calibration mode for endorsing BField status: "
630 if(gainHandle->getNumberOfTags()!=2){
edm::LogError(
"SiStripGainFromCalibTree")<<
"NUMBER OF GAIN TAG IS EXPECTED TO BE 2\n";fflush(stdout);
exit(0);};
631 float newPreviousGain = gainHandle->getApvGain(APV->
APVId,gainHandle->getRange(APV->
DetId, 1),1);
635 float newPreviousGainTick = gainHandle->getApvGain(APV->
APVId,gainHandle->getRange(APV->
DetId, 0),1);
656 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Starting harvesting statistics" << std::endl;
664 if(stag.size()!=0 && stag[0]!=
'_') stag.insert(0,1,
'_');
698 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvi.c_str()
699 <<
", statistics will not be summed!" << std::endl;
702 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Harvesting "
703 << (
Charge_Vs_Index[elepos])->getTH2S()->GetEntries() <<
" more clusters" << std::endl;
712 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTIB.c_str()
713 <<
", statistics will not be summed!" << std::endl;
717 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTOB.c_str()
718 <<
", statistics will not be summed!" << std::endl;
722 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTIDP.c_str()
723 <<
", statistics will not be summed!" << std::endl;
727 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTIDM.c_str()
728 <<
", statistics will not be summed!" << std::endl;
732 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTECP1.c_str()
733 <<
", statistics will not be summed!" << std::endl;
737 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTECP2.c_str()
738 <<
", statistics will not be summed!" << std::endl;
742 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTECM1.c_str()
743 <<
", statistics will not be summed!" << std::endl;
747 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTECM2.c_str()
748 <<
", statistics will not be summed!" << std::endl;
759 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Analyzing calibration tree" << std::endl;
775 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Saving summary into root file" << std::endl;
801 FitResults[0] = -0.5;
803 FitResults[2] = -0.5;
805 FitResults[4] = -0.5;
811 TF1* MyLandau =
new TF1(
"MyLandau",
"landau",LowRange, HighRange);
812 MyLandau->SetParameter(1,300);
813 InputHisto->Fit(MyLandau,
"0QR WW");
816 FitResults[0] = MyLandau->GetParameter(1);
817 FitResults[1] = MyLandau->GetParError(1);
818 FitResults[2] = MyLandau->GetParameter(2);
819 FitResults[3] = MyLandau->GetParError(2);
820 FitResults[4] = MyLandau->GetChisquare() / MyLandau->GetNDF();
821 FitResults[5] = MyLandau->GetParameter(0);
827 if(FitResults[0] <= 0 )
return false;
847 unsigned int FirstAmplitude=0;
848 for(
unsigned int i=0;
i<(*chargeoverpath).size();
i++){
849 FirstAmplitude+=(*nstrips)[
i];
850 int TI = (*trackindex)[
i];
884 bool Saturation =
false;
885 for(
unsigned int s=0;
s<(*nstrips)[
i];
s++){
886 int StripCharge = (*amplitude)[FirstAmplitude-(*nstrips)[
i]+
s];
890 if(StripCharge>1024){
893 }
else if(StripCharge>254){
897 Charge += StripCharge;
901 Charge = (*charge)[
i];
903 Charge = (*charge)[
i]/265.0;
908 double ClusterChargeOverPath = ( (double) Charge )/(*path)[
i] ;
910 if(
Validation) {ClusterChargeOverPath/=(*gainused)[
i];}
927 }
else if(APV->
Eta>0){
940 printf(
"Openning file %3i/%3i --> %s\n",
i+1, (
int)
VInputFiles.size(), (
char*)(
VInputFiles[
i].c_str())); fflush(stdout);
942 TString tree_path = TString::Format(
"gainCalibrationTree%s/tree",
m_calibrationMode.c_str());
943 TTree*
tree =
dynamic_cast<TTree*
> (tfile->Get(tree_path.Data()));
974 unsigned int nentries = tree->GetEntries();
975 printf(
"Number of Events = %i + %i = %i\n",
NEvent,nentries,(
NEvent+nentries));
976 printf(
"Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
977 printf(
"Looping on the Tree :");
978 int TreeStep = nentries/50;
if(TreeStep<=1)TreeStep=1;
979 for (
unsigned int ientry = 0; ientry < tree->GetEntries(); ientry++) {
980 if(ientry%TreeStep==0){printf(
".");fflush(stdout);}
981 tree->GetEntry(ientry);
992 double FitResults[6];
993 double MPVmean = 300;
998 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not execute algoComputeMPVandGain method because "
1000 <<
"Please check if input contains "
1008 printf(
"Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
1009 printf(
"Fitting Charge Distribution :");
1012 if(I%TreeStep==0){printf(
".");fflush(stdout);}
1014 if(APV->
Bin<0) APV->
Bin = chvsidx->GetXaxis()->FindBin(APV->
Index);
1018 Proj = (TH1F*)(chvsidx->ProjectionY(
"",chvsidx->GetXaxis()->FindBin(APV->
Index),chvsidx->GetXaxis()->FindBin(APV->
Index),
"e"));
1023 int SecondAPVId = APV->
APVId;
1024 if(SecondAPVId%2==0){ SecondAPVId = SecondAPVId+1; }
else{ SecondAPVId = SecondAPVId-1; }
1026 if(APV2->
Bin<0) APV2->
Bin = chvsidx->GetXaxis()->FindBin(APV2->
Index);
1027 TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY(
"",APV2->
Bin,APV2->
Bin,
"e"));
1028 if(Proj2){Proj->Add(Proj2,1);
delete Proj2;}
1030 for(
unsigned int i=0;
i<16;
i++){
1031 __gnu_cxx::hash_map<unsigned int, stAPVGain*, __gnu_cxx::hash<unsigned int>,
isEqual >::iterator tmpit;
1036 if(APV2->
Bin<0) APV2->
Bin = chvsidx->GetXaxis()->FindBin(APV2->
Index);
1037 TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY(
"",APV2->
Bin,APV2->
Bin,
"e"));
1038 if(Proj2){Proj->Add(Proj2,1);
delete Proj2;}
1046 APV->
FitMPV = FitResults[0];
1052 APV->
NEntries = Proj->GetEntries();
1071 unsigned int tree_Index;
1072 unsigned int tree_Bin;
1073 unsigned int tree_DetId;
1074 unsigned char tree_APVId;
1075 unsigned char tree_SubDet;
1082 float tree_Thickness;
1084 float tree_FitMPVErr;
1085 float tree_FitWidth;
1086 float tree_FitWidthErr;
1087 float tree_FitChi2NDF;
1090 double tree_PrevGain;
1091 double tree_PrevGainTick;
1092 double tree_NEntries;
1096 MyTree = tfs->
make<TTree> (
"APVGain",
"APVGain");
1097 MyTree->Branch(
"Index" ,&tree_Index ,
"Index/i");
1098 MyTree->Branch(
"Bin" ,&tree_Bin ,
"Bin/i");
1099 MyTree->Branch(
"DetId" ,&tree_DetId ,
"DetId/i");
1100 MyTree->Branch(
"APVId" ,&tree_APVId ,
"APVId/b");
1101 MyTree->Branch(
"SubDet" ,&tree_SubDet ,
"SubDet/b");
1102 MyTree->Branch(
"x" ,&tree_x ,
"x/F");
1103 MyTree->Branch(
"y" ,&tree_y ,
"y/F");
1104 MyTree->Branch(
"z" ,&tree_z ,
"z/F");
1105 MyTree->Branch(
"Eta" ,&tree_Eta ,
"Eta/F");
1106 MyTree->Branch(
"R" ,&tree_R ,
"R/F");
1107 MyTree->Branch(
"Phi" ,&tree_Phi ,
"Phi/F");
1108 MyTree->Branch(
"Thickness" ,&tree_Thickness ,
"Thickness/F");
1109 MyTree->Branch(
"FitMPV" ,&tree_FitMPV ,
"FitMPV/F");
1110 MyTree->Branch(
"FitMPVErr" ,&tree_FitMPVErr ,
"FitMPVErr/F");
1111 MyTree->Branch(
"FitWidth" ,&tree_FitWidth ,
"FitWidth/F");
1112 MyTree->Branch(
"FitWidthErr" ,&tree_FitWidthErr,
"FitWidthErr/F");
1113 MyTree->Branch(
"FitChi2NDF" ,&tree_FitChi2NDF ,
"FitChi2NDF/F");
1114 MyTree->Branch(
"FitNorm" ,&tree_FitNorm ,
"FitNorm/F");
1115 MyTree->Branch(
"Gain" ,&tree_Gain ,
"Gain/D");
1116 MyTree->Branch(
"PrevGain" ,&tree_PrevGain ,
"PrevGain/D");
1117 MyTree->Branch(
"PrevGainTick" ,&tree_PrevGainTick,
"PrevGainTick/D");
1118 MyTree->Branch(
"NEntries" ,&tree_NEntries ,
"NEntries/D");
1119 MyTree->Branch(
"isMasked" ,&tree_isMasked ,
"isMasked/O");
1122 FILE* Gains = stdout;
1123 fprintf(Gains,
"NEvents = %i\n",
NEvent);
1124 fprintf(Gains,
"NTracks = %i\n",
NTrack);
1127 fprintf(Gains,
"Number of Pixel Dets = %lu\n",static_cast<unsigned long>(
NPixelDets));
1128 fprintf(Gains,
"Number of Strip APVs = %lu\n",static_cast<unsigned long>(
NStripAPVs));
1132 fprintf(Gains,
"NEvents = %i\n",
NEvent);
1133 fprintf(Gains,
"NTracks = %i\n",
NTrack);
1136 fprintf(Gains,
"Number of Strip APVs = %lu\n",static_cast<unsigned long>(
NStripAPVs));
1137 fprintf(Gains,
"Number of Pixel Dets = %lu\n",static_cast<unsigned long>(
NPixelDets));
1144 if(APV==
NULL)
continue;
1148 tree_Index = APV->
Index;
1150 tree_DetId = APV->
DetId;
1151 tree_APVId = APV->
APVId;
1152 tree_SubDet = APV->
SubDet;
1156 tree_Eta = APV->
Eta;
1158 tree_Phi = APV->
Phi;
1160 tree_FitMPV = APV->
FitMPV;
1164 tree_FitChi2NDF = APV->
FitChi2;
1166 tree_Gain = APV->
Gain;
1173 if(tree_DetId==402673324){
1174 printf(
"%i | %i : %f --> %f (%f)\n", tree_DetId, tree_APVId, tree_PrevGain, tree_Gain, tree_NEntries);
1180 if(Gains)fclose(Gains);
1191 edm::LogError(
"SiStripGainFromCalibTree") <<
"produceTagFilter -> Return false: could not retrieve the "
1193 <<
"Please check if input contains "
1203 <<
"produceTagFilter -> Return false: Statistics is too low : " << integral << endl;
1209 <<
"produceTagFilter -> Return false: ratio of GOOD/TOTAL is too low: " << (1.0 *
GOOD) / (
GOOD+
BAD) << endl;
1221 edm::LogWarning(
"SiStripGainFromCalibTree")<<
"getNewObject -> will not produce a paylaod because produceTagFilter returned false " << endl;
1227 std::vector<float>* theSiStripVector =
NULL;
1228 unsigned int PreviousDetId = 0;
1231 if(APV==
NULL){ printf(
"Bug\n");
continue; }
1232 if(APV->
SubDet<=2)
continue;
1233 if(APV->
DetId != PreviousDetId){
1234 if(theSiStripVector!=
NULL){
1236 if ( !obj->
put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
1238 theSiStripVector =
new std::vector<float>;
1239 PreviousDetId = APV->
DetId;
1241 theSiStripVector->push_back(APV->
Gain);
1243 if(theSiStripVector!=
NULL){
1245 if ( !obj->
put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
1259 TChain* t1 =
new TChain(
"SiStripCalib/APVGain");
1262 unsigned int tree_DetId;
1263 unsigned char tree_APVId;
1266 t1->SetBranchAddress(
"DetId" ,&tree_DetId );
1267 t1->SetBranchAddress(
"APVId" ,&tree_APVId );
1268 t1->SetBranchAddress(
"Gain" ,&tree_Gain );
1270 for (
unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
1271 t1->GetEntry(ientry);
edm::EDGetTokenT< std::vector< int > > trackindex_token_
std::vector< MonitorElement * > Charge_Vs_Index
T getParameter(std::string const &) const
EventNumber_t event() const
void swapBFieldMode(void)
virtual int nstrips() const =0
T getUntrackedParameter(std::string const &, T const &) const
std::vector< string > dqm_tag_
const std::vector< float > * trackp
unsigned int MinTrackHits
edm::EDGetTokenT< std::vector< double > > tracketa_token_
edm::EDGetTokenT< std::vector< unsigned char > > amplitude_token_
const std::vector< double > * chargeoverpath
edm::EDGetTokenT< std::vector< unsigned int > > rawid_token_
const std::vector< unsigned char > * amplitude
bool isBFieldConsistentWithMode(const edm::EventSetup &iSetup) const
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
SiStripApvGain * getNewObject() override
virtual int ncolumns() const =0
const std::vector< double > * localdirz
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const std::vector< double > * trackchi2ndof
virtual void algoBeginRun(const edm::Run &run, const edm::EventSetup &iSetup) override
const std::vector< double > * localdirx
~SiStripGainFromCalibTree()
dispatcher processEvent(e, inputTag, standby)
#define DEFINE_FWK_MODULE(type)
unsigned int NClusterPixel
virtual void algoEndRun(const edm::Run &run, const edm::EventSetup &iSetup) override
const std::vector< unsigned int > * rawid
edm::EDGetTokenT< std::vector< bool > > overlapping_token_
double tagCondition_GoodFrac
SiStripGainFromCalibTree(const edm::ParameterSet &)
edm::Handle< T > connect(const T *&ptr, edm::EDGetTokenT< T > token, const edm::Event &evt)
virtual int nrows() const =0
const std::vector< int > * trackalgo
std::vector< MonitorElement * > Charge_Vs_PathlengthTOB
void storeOnTree(TFileService *tfs)
T * make(const Args &...args) const
make new ROOT object
const std::vector< float > * trackpt
std::vector< MonitorElement * > Charge_Vs_PathlengthTECM1
const std::vector< unsigned int > * trackhitsvalid
void MakeCalibrationMap()
std::vector< MonitorElement * > Charge_Vs_PathlengthTECM2
double MaxTrackChiOverNdf
edm::EDGetTokenT< std::vector< bool > > farfromedge_token_
bool put(const uint32_t &detID, Range input)
uint32_t rawId() const
get the raw id
edm::EDGetTokenT< std::vector< unsigned int > > trackhitsvalid_token_
T x() const
Cartesian x coordinate.
std::vector< stAPVGain * > APVsCollOrdered
__gnu_cxx::hash_map< unsigned int, stAPVGain *, __gnu_cxx::hash< unsigned int >, isEqual > APVsColl
edm::EDGetTokenT< std::vector< double > > path_token_
void algoComputeMPVandGain()
edm::EDGetTokenT< std::vector< int > > trackalgo_token_
edm::EDGetTokenT< std::vector< float > > trackp_token_
bool IsGoodLandauFit(double *FitResults)
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
virtual void algoBeginJob(const edm::EventSetup &iSetup) override
std::pair< ContainerIterator, ContainerIterator > Range
edm::EDGetTokenT< std::vector< bool > > TrigTech_token_
edm::EDGetTokenT< std::vector< double > > chargeoverpath_token_
const std::complex< double > I
const std::vector< double > * gainused
std::vector< MonitorElement * > Charge_Vs_PathlengthTECP1
edm::EDGetTokenT< std::vector< double > > localdirz_token_
const std::vector< unsigned short > * firststrip
std::vector< MonitorElement * > Charge_Vs_PathlengthTIDM
const std::vector< double > * localdiry
edm::EDGetTokenT< std::vector< unsigned int > > charge_token_
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
Integral< F, X >::type integral(const F &f)
vector< string > VInputFiles
virtual void algoEndJob() override
edm::EDGetTokenT< std::vector< unsigned short > > nstrips_token_
std::vector< MonitorElement * > Charge_Vs_PathlengthTECP2
const std::vector< int > * trackindex
int statCollectionFromMode(const char *tag) const
std::vector< MonitorElement * > Charge_Vs_PathlengthTIB
edm::EDGetTokenT< std::vector< unsigned short > > firststrip_token_
virtual void algoAnalyze(const edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< std::vector< float > > trackpt_token_
T const * product() const
const std::vector< bool > * overlapping
const std::vector< bool > * saturation
bool merge(LuminosityBlockRange &lh, LuminosityBlockRange &rh)
void getPeakOfLandau(TH1 *InputHisto, double *FitResults, double LowRange=50, double HighRange=5400)
T const * product() const
void algoAnalyzeTheTree()
const std::vector< bool > * farfromedge
const std::vector< bool > * TrigTech
void setDoStore(const bool doStore)
When set to false the payload will not be written to the db.
double tagCondition_NClusters
edm::EDGetTokenT< std::vector< double > > localdirx_token_
edm::EDGetTokenT< std::vector< bool > > saturation_token_
edm::EDGetTokenT< std::vector< double > > trackchi2ndof_token_
std::vector< MonitorElement * > Charge_Vs_PathlengthTIDP
edm::EDGetTokenT< std::vector< double > > localdiry_token_
volatile std::atomic< bool > shutdown_flag false
const std::vector< unsigned int > * charge
const std::vector< double > * path
const std::vector< double > * trackphi
const std::vector< unsigned short > * nstrips
edm::EDGetTokenT< std::vector< double > > gainused_token_
void bookDQMHistos(const char *dqm_dir, const char *tag)
edm::EDGetTokenT< std::vector< double > > trackphi_token_
const std::vector< double > * tracketa
unsigned int NClusterStrip
void merge(TH2 *A, TH2 *B)