69 #include "TObjString.h" 79 #include <unordered_map> 109 double PreviousGainTick;
128 virtual void algoEndJob ()
override;
131 int statCollectionFromMode(
const char*
tag)
const;
132 void bookDQMHistos(
const char* dqm_dir,
const char* tag);
135 void swapBFieldMode(
void);
138 void algoAnalyzeTheTree();
139 void algoComputeMPVandGain();
142 void getPeakOfLandau(TH1* InputHisto,
double* FitResults,
double LowRange=50,
double HighRange=5400);
143 bool IsGoodLandauFit(
double* FitResults);
145 void MakeCalibrationMap();
146 bool produceTagFilter();
224 unsigned int eventnumber =0;
264 std::unordered_map<unsigned int, stAPVGain*>
APVsColl;
270 std::vector<string>::const_iterator it=dqm_tag_.begin();
271 while(it!=dqm_tag_.end()) {
272 if(*it==
std::string(tag))
return it-dqm_tag_.begin();
282 if(A->GetNbinsX() == B->GetNbinsX()){
285 for(
int x=0;
x<=B->GetNbinsX()+1;
x++){
286 for(
int y=0;y<=B->GetNbinsY()+1; y++){
287 A->SetBinContent(
x,y,A->GetBinContent(
x,y)+B->GetBinContent(
x,y));
387 EventPrefix_ = evtinfo_pset.getUntrackedParameter<
string>(
"prefix");
388 EventSuffix_ = evtinfo_pset.getUntrackedParameter<
string>(
"suffix");
393 TrackPrefix_ = track_pset.getUntrackedParameter<
string>(
"prefix");
394 TrackSuffix_ = track_pset.getUntrackedParameter<
string>(
"suffix");
407 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Setting " << dqm_dir <<
"in DQM and booking histograms for tag " 412 dbe->setCurrentFolder(dqm_dir);
416 if(stag.size()!=0 && stag[0]!=
'_') stag.insert(0,1,
'_');
431 Charge_Vs_Index[elepos] =
dbe->book2S(cvi.c_str() , cvi.c_str() , 88625, 0 , 88624,2000,0,4000);
450 const char * dqm_dir =
"AlCaReco/SiStripGainsHarvesting/";
457 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Switching calibration mode for endorsing BField status: " 468 auto const &
Det = tkGeom->dets();
472 unsigned int Index=0;
473 for(
unsigned int i=0;
i<
Det.size();
i++){
481 if(!DetUnit)
continue;
484 unsigned int NAPV = Topo.
nstrips()/128;
486 for(
unsigned int j=0;j<NAPV;j++){
502 APV->
x = DetUnit->position().basicVector().x();
503 APV->
y = DetUnit->position().basicVector().y();
504 APV->
z = DetUnit->position().basicVector().z();
505 APV->
Eta = DetUnit->position().basicVector().eta();
506 APV->
Phi = DetUnit->position().basicVector().phi();
507 APV->
R = DetUnit->position().basicVector().transverse();
508 APV->
Thickness = DetUnit->surface().bounds().thickness();
520 for(
unsigned int i=0;
i<
Det.size();
i++){
525 if(!DetUnit)
continue;
528 unsigned int NROCRow = Topo.
nrows()/(80.);
529 unsigned int NROCCol = Topo.
ncolumns()/(52.);
531 for(
unsigned int j=0;j<NROCRow;j++){
532 for(
unsigned int i=0;
i<NROCCol;
i++){
548 APV->
x = DetUnit->position().basicVector().x();
549 APV->
y = DetUnit->position().basicVector().y();
550 APV->
z = DetUnit->position().basicVector().z();
551 APV->
Eta = DetUnit->position().basicVector().eta();
552 APV->
Phi = DetUnit->position().basicVector().phi();
553 APV->
R = DetUnit->position().basicVector().transverse();
554 APV->
Thickness = DetUnit->surface().bounds().thickness();
588 return ( (isOn && !is0T) || (!isOn && is0T) );
606 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Switching calibration mode for endorsing BField status: " 635 edm::LogWarning(
"SiStripGainFromCalibTree")<<
"WARNING: TickMarkGain in the global tag changed\n"<< std::endl
636 <<
" APV->SubDet: "<< APV->
SubDet <<
" APV->APVId:" << APV->
APVId << std::endl
637 <<
" APV->PreviousGainTick: "<<APV->
PreviousGainTick<<
" newPreviousGainTick: "<<newPreviousGainTick<<std::endl;
655 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Starting harvesting statistics" << std::endl;
663 if(stag.size()!=0 && stag[0]!=
'_') stag.insert(0,1,
'_');
697 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvi.c_str()
698 <<
", statistics will not be summed!" << std::endl;
701 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Harvesting " 702 << (
Charge_Vs_Index[elepos])->getTH2S()->GetEntries() <<
" more clusters" << std::endl;
711 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTIB.c_str()
712 <<
", statistics will not be summed!" << std::endl;
716 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTOB.c_str()
717 <<
", statistics will not be summed!" << std::endl;
721 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTIDP.c_str()
722 <<
", statistics will not be summed!" << std::endl;
726 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTIDM.c_str()
727 <<
", statistics will not be summed!" << std::endl;
731 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTECP1.c_str()
732 <<
", statistics will not be summed!" << std::endl;
736 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTECP2.c_str()
737 <<
", statistics will not be summed!" << std::endl;
741 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTECM1.c_str()
742 <<
", statistics will not be summed!" << std::endl;
746 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not retrieve " << cvpTECM2.c_str()
747 <<
", statistics will not be summed!" << std::endl;
758 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Analyzing calibration tree" << std::endl;
774 edm::LogInfo(
"SiStripGainFromCalibTree") <<
"Saving summary into root file" << std::endl;
800 FitResults[0] = -0.5;
802 FitResults[2] = -0.5;
804 FitResults[4] = -0.5;
810 TF1* MyLandau =
new TF1(
"MyLandau",
"landau",LowRange, HighRange);
811 MyLandau->SetParameter(1,300);
812 InputHisto->Fit(MyLandau,
"0QR WW");
815 FitResults[0] = MyLandau->GetParameter(1);
816 FitResults[1] = MyLandau->GetParError(1);
817 FitResults[2] = MyLandau->GetParameter(2);
818 FitResults[3] = MyLandau->GetParError(2);
819 FitResults[4] = MyLandau->GetChisquare() / MyLandau->GetNDF();
820 FitResults[5] = MyLandau->GetParameter(0);
826 if(FitResults[0] <= 0 )
return false;
846 unsigned int FirstAmplitude=0;
847 for(
unsigned int i=0;
i<(*chargeoverpath).size();
i++){
848 FirstAmplitude+=(*nstrips)[
i];
849 int TI = (*trackindex)[
i];
883 bool Saturation =
false;
884 for(
unsigned int s=0;
s<(*nstrips)[
i];
s++){
885 int StripCharge = (*amplitude)[FirstAmplitude-(*nstrips)[
i]+
s];
889 if(StripCharge>1024){
892 }
else if(StripCharge>254){
896 Charge += StripCharge;
900 Charge = (*charge)[
i];
902 Charge = (*charge)[
i]/265.0;
907 double ClusterChargeOverPath = ( (double) Charge )/(*path)[
i] ;
909 if(
Validation) {ClusterChargeOverPath/=(*gainused)[
i];}
926 }
else if(APV->
Eta>0){
939 printf(
"Openning file %3i/%3i --> %s\n",
i+1, (
int)
VInputFiles.size(), (
char*)(
VInputFiles[
i].c_str())); fflush(stdout);
941 TString tree_path = TString::Format(
"gainCalibrationTree%s/tree",
m_calibrationMode.c_str());
942 TTree*
tree =
dynamic_cast<TTree*
> (tfile->Get(tree_path.Data()));
973 unsigned int nentries = tree->GetEntries();
974 printf(
"Number of Events = %i + %i = %i\n",
NEvent,nentries,(
NEvent+nentries));
975 printf(
"Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
976 printf(
"Looping on the Tree :");
977 int TreeStep = nentries/50;
if(TreeStep<=1)TreeStep=1;
978 for (
unsigned int ientry = 0; ientry < tree->GetEntries(); ientry++) {
979 if(ientry%TreeStep==0){printf(
".");fflush(stdout);}
980 tree->GetEntry(ientry);
991 double FitResults[6];
992 double MPVmean = 300;
997 edm::LogError(
"SiStripGainFromCalibTree") <<
"Harvesting: could not execute algoComputeMPVandGain method because " 999 <<
"Please check if input contains " 1007 printf(
"Progressing Bar :0%% 20%% 40%% 60%% 80%% 100%%\n");
1008 printf(
"Fitting Charge Distribution :");
1011 if(I%TreeStep==0){printf(
".");fflush(stdout);}
1013 if(APV->
Bin<0) APV->
Bin = chvsidx->GetXaxis()->FindBin(APV->
Index);
1017 Proj = (TH1F*)(chvsidx->ProjectionY(
"",chvsidx->GetXaxis()->FindBin(APV->
Index),chvsidx->GetXaxis()->FindBin(APV->
Index),
"e"));
1022 int SecondAPVId = APV->
APVId;
1023 if(SecondAPVId%2==0){ SecondAPVId = SecondAPVId+1; }
else{ SecondAPVId = SecondAPVId-1; }
1025 if(APV2->
Bin<0) APV2->
Bin = chvsidx->GetXaxis()->FindBin(APV2->
Index);
1026 TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY(
"",APV2->
Bin,APV2->
Bin,
"e"));
1027 if(Proj2){Proj->Add(Proj2,1);
delete Proj2;}
1029 for(
unsigned int i=0;
i<16;
i++){
1034 if(APV2->
Bin<0) APV2->
Bin = chvsidx->GetXaxis()->FindBin(APV2->
Index);
1035 TH1F* Proj2 = (TH1F*)(chvsidx->ProjectionY(
"",APV2->
Bin,APV2->
Bin,
"e"));
1036 if(Proj2){Proj->Add(Proj2,1);
delete Proj2;}
1044 APV->
FitMPV = FitResults[0];
1050 APV->
NEntries = Proj->GetEntries();
1069 unsigned int tree_Index;
1070 unsigned int tree_Bin;
1071 unsigned int tree_DetId;
1072 unsigned char tree_APVId;
1073 unsigned char tree_SubDet;
1080 float tree_Thickness;
1082 float tree_FitMPVErr;
1083 float tree_FitWidth;
1084 float tree_FitWidthErr;
1085 float tree_FitChi2NDF;
1088 double tree_PrevGain;
1089 double tree_PrevGainTick;
1090 double tree_NEntries;
1094 MyTree = tfs->
make<TTree> (
"APVGain",
"APVGain");
1095 MyTree->Branch(
"Index" ,&tree_Index ,
"Index/i");
1096 MyTree->Branch(
"Bin" ,&tree_Bin ,
"Bin/i");
1097 MyTree->Branch(
"DetId" ,&tree_DetId ,
"DetId/i");
1098 MyTree->Branch(
"APVId" ,&tree_APVId ,
"APVId/b");
1099 MyTree->Branch(
"SubDet" ,&tree_SubDet ,
"SubDet/b");
1100 MyTree->Branch(
"x" ,&tree_x ,
"x/F");
1101 MyTree->Branch(
"y" ,&tree_y ,
"y/F");
1102 MyTree->Branch(
"z" ,&tree_z ,
"z/F");
1103 MyTree->Branch(
"Eta" ,&tree_Eta ,
"Eta/F");
1104 MyTree->Branch(
"R" ,&tree_R ,
"R/F");
1105 MyTree->Branch(
"Phi" ,&tree_Phi ,
"Phi/F");
1106 MyTree->Branch(
"Thickness" ,&tree_Thickness ,
"Thickness/F");
1107 MyTree->Branch(
"FitMPV" ,&tree_FitMPV ,
"FitMPV/F");
1108 MyTree->Branch(
"FitMPVErr" ,&tree_FitMPVErr ,
"FitMPVErr/F");
1109 MyTree->Branch(
"FitWidth" ,&tree_FitWidth ,
"FitWidth/F");
1110 MyTree->Branch(
"FitWidthErr" ,&tree_FitWidthErr,
"FitWidthErr/F");
1111 MyTree->Branch(
"FitChi2NDF" ,&tree_FitChi2NDF ,
"FitChi2NDF/F");
1112 MyTree->Branch(
"FitNorm" ,&tree_FitNorm ,
"FitNorm/F");
1113 MyTree->Branch(
"Gain" ,&tree_Gain ,
"Gain/D");
1114 MyTree->Branch(
"PrevGain" ,&tree_PrevGain ,
"PrevGain/D");
1115 MyTree->Branch(
"PrevGainTick" ,&tree_PrevGainTick,
"PrevGainTick/D");
1116 MyTree->Branch(
"NEntries" ,&tree_NEntries ,
"NEntries/D");
1117 MyTree->Branch(
"isMasked" ,&tree_isMasked ,
"isMasked/O");
1120 FILE* Gains = stdout;
1121 fprintf(Gains,
"NEvents = %i\n",
NEvent);
1122 fprintf(Gains,
"NTracks = %i\n",
NTrack);
1125 fprintf(Gains,
"Number of Pixel Dets = %lu\n",static_cast<unsigned long>(
NPixelDets));
1126 fprintf(Gains,
"Number of Strip APVs = %lu\n",static_cast<unsigned long>(
NStripAPVs));
1130 fprintf(Gains,
"NEvents = %i\n",
NEvent);
1131 fprintf(Gains,
"NTracks = %i\n",
NTrack);
1134 fprintf(Gains,
"Number of Strip APVs = %lu\n",static_cast<unsigned long>(
NStripAPVs));
1135 fprintf(Gains,
"Number of Pixel Dets = %lu\n",static_cast<unsigned long>(
NPixelDets));
1142 if(APV==
NULL)
continue;
1146 tree_Index = APV->
Index;
1148 tree_DetId = APV->
DetId;
1149 tree_APVId = APV->
APVId;
1150 tree_SubDet = APV->
SubDet;
1154 tree_Eta = APV->
Eta;
1156 tree_Phi = APV->
Phi;
1158 tree_FitMPV = APV->
FitMPV;
1162 tree_FitChi2NDF = APV->
FitChi2;
1164 tree_Gain = APV->
Gain;
1171 if(tree_DetId==402673324){
1172 printf(
"%i | %i : %f --> %f (%f)\n", tree_DetId, tree_APVId, tree_PrevGain, tree_Gain, tree_NEntries);
1178 if(Gains)fclose(Gains);
1189 edm::LogError(
"SiStripGainFromCalibTree") <<
"produceTagFilter -> Return false: could not retrieve the " 1191 <<
"Please check if input contains " 1201 <<
"produceTagFilter -> Return false: Statistics is too low : " << integral << endl;
1207 <<
"produceTagFilter -> Return false: ratio of GOOD/TOTAL is too low: " << (1.0 *
GOOD) / (
GOOD+
BAD) << endl;
1219 edm::LogWarning(
"SiStripGainFromCalibTree")<<
"getNewObject -> will not produce a paylaod because produceTagFilter returned false " << endl;
1225 std::vector<float>* theSiStripVector =
NULL;
1226 unsigned int PreviousDetId = 0;
1229 if(APV==
NULL){ printf(
"Bug\n");
continue; }
1230 if(APV->
SubDet<=2)
continue;
1231 if(APV->
DetId != PreviousDetId){
1232 if(theSiStripVector!=
NULL){
1234 if ( !obj->
put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
1236 theSiStripVector =
new std::vector<float>;
1237 PreviousDetId = APV->
DetId;
1239 theSiStripVector->push_back(APV->
Gain);
1241 if(theSiStripVector!=
NULL){
1243 if ( !obj->
put(PreviousDetId,range) ) printf(
"Bug to put detId = %i\n",PreviousDetId);
1257 TChain* t1 =
new TChain(
"SiStripCalib/APVGain");
1260 unsigned int tree_DetId;
1261 unsigned char tree_APVId;
1264 t1->SetBranchAddress(
"DetId" ,&tree_DetId );
1265 t1->SetBranchAddress(
"APVId" ,&tree_APVId );
1266 t1->SetBranchAddress(
"Gain" ,&tree_Gain );
1268 for (
unsigned int ientry = 0; ientry < t1->GetEntries(); ientry++) {
1269 t1->GetEntry(ientry);
bool IsApvBad(const uint32_t &detid, const short &apvNb) const
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)
T getUntrackedParameter(std::string const &, T const &) const
std::vector< string > dqm_tag_
virtual int nrows() const =0
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
SiStripApvGain * getNewObject() override
const std::vector< double > * localdirz
size_t getNumberOfTags() const
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)
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
static float getApvGain(const uint16_t &apv, const SiStripApvGain::Range &range)
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
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)
std::unordered_map< unsigned int, stAPVGain * > APVsColl
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::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
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)
def elem(elemtype, innerHTML='', html_class='', kwargs)
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
virtual int nstrips() const =0
bool merge(LuminosityBlockRange &lh, LuminosityBlockRange &rh)
void getPeakOfLandau(TH1 *InputHisto, double *FitResults, double LowRange=50, double HighRange=5400)
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.
virtual int ncolumns() const =0
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_
const std::vector< unsigned int > * charge
const std::vector< double > * path
const std::vector< double > * trackphi
const std::vector< unsigned short > * nstrips
T const * product() const
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)
const SiStripApvGain::Range getRange(uint32_t detID) const